package com.wjtc.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wjtc.common.base.restful.Page;
import com.wjtc.service.entity.QuestionResult;
import com.wjtc.service.inter.QuestionService;
import com.wjtc.service.mapping.QuestionResultMapper;
import com.wjtc.web.model.QuestionPageModel;

@Service
public class QuestionServiceImpl implements QuestionService {
	@Autowired
	private QuestionResultMapper questionResultMapper;

	@Override
	public int saveQuestion(QuestionResult result) {

		return questionResultMapper.insert(result);
	}

	@Override
	public QuestionResult findQuestionResultByPk(String id) {

		return questionResultMapper.selectByPrimaryKey(id);
	}

	@Override
	public Page queryAllListByPage(QuestionPageModel model) {
		Map<String, Object> params = model.getParams();
		PageHelper.startPage(model.getPageNumber(), model.getLimit());
		List<Map<String, Object>> l = questionResultMapper.queryAllListByParams(params);
		com.github.pagehelper.Page<Map<String, Object>>  pg = (com.github.pagehelper.Page<Map<String, Object>>)l;
		Page rtpage = new Page();
		rtpage.setRows(l);
		rtpage.setTotal(pg.getTotal());
		return rtpage;
	}

	@Override
	public List<Map<String, Object>> queryAllList(QuestionPageModel model) {
		Map<String, Object> params = model.getParams();
		return questionResultMapper.queryAllListByParams(params);
	}

}
